package com.wang.wx.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wang.wx.entity.WxUser;
import com.wang.wx.mapper.WxUserMapper;
import com.wang.wx.service.WxUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * (WxUser)表服务实现类
 *
 * @author makejava
 * @since 2024-08-02 14:53:25
 */
@Slf4j
@Service
public class WxUserServiceImpl extends ServiceImpl<WxUserMapper, WxUser> implements WxUserService {
    
    @Resource
    private WxUserMapper wxUserMapper;

    @Override
    public void createIndexes() {
        log.info("正在创建微信分表的索引");
        wxUserMapper.createIndexes();
        log.info("微信索引创建成功");
    }

    public void dropIndexes() {
        wxUserMapper.dropIndexes();
        log.info("微信索引删除成功");
    }

    @Override
    public List<WxUser> getByPhone(String phone) {
        LambdaQueryWrapper<WxUser> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(WxUser::getPhone, phone);
        List<WxUser> wxUsers = this.list(wrapper);
        if (ObjectUtil.isNotEmpty(wxUsers)) {
            return wxUsers;
        }
        return Collections.emptyList();
    }
}

